﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Outils;
using FichierTxt;
using projet_fichier_objet;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace App_Recherche
{
    public partial class Affichage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Agence = Request.QueryString["Ag"];
            int CodeAg = 0;

            if (int.TryParse(Agence, out CodeAg))
            {
                List<Personne> ListInterimaire = new List<Personne>();
                //string CnxInterimaire = "Data Source=PILOTT-LGZ;Initial Catalog=Interimaires;Integrated Security=True;Pooling=False";
                SqlConnection SqlC = new SqlConnection(Utils.CnxInterimaire);

                SqlC.Open();

                SqlCommand SQLCmd = SqlC.CreateCommand();
                if (CodeAg != 0)
                {
                    SQLCmd.CommandText = " SELECT * FROM Interimaire WHERE agence = '" + CodeAg + "'";
                }
                else
                {
                    SQLCmd.CommandText = " SELECT * FROM Interimaire";
                }

                SqlDataReader SqlReader = SQLCmd.ExecuteReader();
                while (SqlReader.Read() && SqlReader != null)
                {
                    Personne Candidat = new Personne();
                    Candidat.ID = (int)SqlReader["Id"];
                    Candidat.Nom = (string)SqlReader["Nom"];
                    Candidat.Email = (string)SqlReader["Email"];
                    Candidat.Ville = (string)SqlReader["Ville"];
                    Candidat.CodeAgence = (int)SqlReader["Agence"];
                    Candidat.DateNaissance = Convert.ToDateTime(SqlReader["Datenaiss"]);
                    ListInterimaire.Add(Candidat);
                }

                SqlC.Close();
                //transmet la liste interimaire complété
                rptPersonnes.Personnes = ListInterimaire;
            }
        }
    }
}
